package com.wfy.controller;

import com.wfy.pojo.GoodsEs;
import com.wfy.pojo.PageResult;
import com.wfy.pojo.SearchRequest;
import com.wfy.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Title: SearchController
 * @Package com.wfy.controller
 * @Author 王飞遥
 * @Date 2022/9/19 20:56
 */
@RestController
@RequestMapping("/es")
public class SearchController {
    @Autowired
    SearchService searchService;
    @RequestMapping("/page")
    public ResponseEntity<PageResult<GoodsEs>> search(@RequestBody SearchRequest searchRequest){
        PageResult<GoodsEs>page =  searchService.search(searchRequest);
        if(page==null){
            return new ResponseEntity<>(HttpStatus.NOT_FOUND);//没有找到数据
        }
        return ResponseEntity.ok(page);
    }
}
